package graph;

import java.util.List;

import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;

public class SearcherOfAlreadyExistingInterfaceOfClassWithSpecifiedMethods {
	
	public static ITypeBinding getInterface(ITypeBinding implementingClass, List<IMethodBinding> methodBindings){
		ITypeBinding foundInterface = null;
		System.out.print("SearcherOfAlreadyExistingInterfaceOfClassWithSpecifiedMethods>searching for methods ");
		for (IMethodBinding meth:methodBindings)
			System.out.print(meth.toString()+" ");
		System.out.println();
		ITypeBinding[] interfaces = implementingClass.getInterfaces();
		System.out.println("SearcherOfAlreadyExistingInterfaceOfClassWithSpecifiedMethods>class "+implementingClass.getQualifiedName()+" realizes "+interfaces.length+" interfaces");
        for (ITypeBinding interf:implementingClass.getInterfaces()) {
        	System.out.print("SearcherOfAlreadyExistingInterfaceOfClassWithSpecifiedMethods>among "+interf.getQualifiedName());
        	for (IMethodBinding methOfInterf:interf.getDeclaredMethods())
        		System.out.print(methOfInterf.toString()+" ");
        	System.out.println();
        	int interfaceContains = 0;
        	for (IMethodBinding meth:methodBindings)
        		for (IMethodBinding methOfInterf:interf.getDeclaredMethods())
        			if (meth.isSubsignature(methOfInterf)) {//(Bindings.equals(meth, methOfInterf)) {//(areEqual(meth,methOfInterf))
        				interfaceContains++;
        				System.out.println("SearcherOfAlreadyExistingInterfaceOfClassWithSpecifiedMethods>"+meth.getName()+" and "+methOfInterf.getName()+" are similar.");
        			}
        	if (interfaceContains==methodBindings.size()) {
        		foundInterface=interf;
        		break;
        	}
        }
        return foundInterface;
	}
}
